<script>
	import checkVersion from '@/uni_modules/uni-upgrade-center-app/utils/check-update.js';
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		methods: {
			...mapMutations(['login']),
			//未读信息
			
			getunreadnumber(){
				//#ifdef APP-PLUS
				this.$api.getunreadnumber().then((res) => {
					console.log(res.data.dataMap)
					let num = res.data.dataMap
					plus.runtime.setBadgeNumber(num);     		
				})	
				//#endif
			},
		
		},
		computed: mapState(['loginState']),
		onLaunch: function() {


			checkVersion()
			//#ifdef APP-PLUS
			const _self = this;
			const _handlePush = function(message) {
				// TODO  
				// uni.showToast({
				// 	title: JSON.stringify(message),
				// 	icon:'none',
				// 	duration:10000
				// })
				
				uni.switchTab({
					url: '/pages/message/message'
				});
			};
			plus.push.addEventListener('click', _handlePush);
			plus.push.addEventListener('receive', _handlePush);


			// 获取客户端标识
			let pinf = plus.push.getClientInfo();
			let cid = pinf && pinf.clientid || '';
			uni.setStorageSync('clientId', cid);
			// 获取软件版本
			plus.runtime.getProperty(plus.runtime.appid, function(wgtinfo) {
				//  获取 app的version
				let appversion = wgtinfo.version;
				// 存缓存 版本号
				try {
					uni.setStorageSync('appversion', appversion);
				} catch (e) {}
				console.log("appversion:" + appversion);
			});
			//#endif
			// 验证用户的登陆状态
			let _this = this
			let unserInfo = uni.getStorageSync("userInfo")
			if (unserInfo != '') {
				//通过token验证用户信息是否过期
				uni.getStorage({
					key: 'userInfo',
					success(res) {
						console.log("========" + res.data)
						_this.login(res.data)
						//验证登录是否过期
						_this.$api.checkLogin({}).then((res) => {
							if (res.data.success) {
								this.loginState = true
							}

						})
					}
				})


			}

		},
		onLoad: function() {


		},
		onShow: function() {
			this.getunreadnumber()
			console.log('App Show')
			//#ifdef APP-PLUS
			if (plus.navigator.hasNotchInScreen()) {
				uni.setStorageSync("isBang", true)
			} else {
				uni.setStorageSync("isBang", false)
			}
			//#endif

		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style>
	/*每个页面公共css */
	/* 官方ui库 */
	@import "/common/uni.css";
	/* 第三方动画库 */
	@import "/common/animate.css";
	/* 自定义图标库 */
	@import "/common/icon.css";
	/* UI基础库 */
	@import "/common/zcm-main.css";
	/* 公共样式 */
	@import "/common/common.css";
</style>
